//
//  FCMineViewController.swift
//  FinancialConsulting
//
//  Created by Max on 2017/10/26.
//  Copyright © 2017年 com.vector. All rights reserved.
//

import UIKit

class FCMineViewController: FCViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet weak var userLabel: UILabel!
    @IBOutlet weak var tabelView: UITableView!
    override func viewDidLoad() {
        super.viewDidLoad()

        
        tabelView.tableFooterView = UIView()
        if self.navigationItem.leftBarButtonItem != nil {
            let btn = UIButton(type: UIButtonType.custom)
            self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
        }
        
        if FCModelData.instance.isLogin == true {
            userLabel.text = FCModelData.instance.userName
            
            
        }else {
        
            
            if let v = FCLoginViewController.create() as? FCLoginViewController {
                
                self.navigationController?.isNavigationBarHidden = true
                v.hidesBottomBarWhenPushed = true
                self.navigationController?.pushViewController(v, animated: true)
                
                
                
            }

        }
        
        
        
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
     
        return 4
    
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
       
        return 44
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = UITableViewCell()
       
        cell = tableView.dequeueReusableCell(withIdentifier: FCMineCell.name,for: indexPath)
        
        if let mienCell = cell as? FCMineCell {
        mienCell.accessoryType = .disclosureIndicator
            if indexPath.row == 0 {
                mienCell.titleLable.text = "我的消息"
                mienCell.titleButton.setImage(UIImage(named:"15"), for: .normal)
            }else if indexPath.row == 1 {
                mienCell.titleLable.text = "用户反馈"
                mienCell.titleButton.setImage(UIImage(named:"16"), for: .normal)
            }else if indexPath.row == 2 {
                mienCell.titleLable.text = "关于我们"
                mienCell.titleButton.setImage(UIImage(named:"17"), for: .normal)
            }else {
                mienCell.focusButton.isHidden = false
                mienCell.titleLable.text = "关注微信公众号"
                mienCell.titleButton.setImage(UIImage(named:"18"), for: .normal)
            }

       }
        
       
        return cell
    
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == 1 {
            if let v = FCFeedBackViewController.create() as? FCFeedBackViewController {
            
                v.hidesBottomBarWhenPushed = true
             self.navigationController?.pushViewController(v, animated: true)
            }
        
        
        }else if indexPath.row == 2 {
            if let v = FCAboutUsViewController.create() as? FCAboutUsViewController {
                v.hidesBottomBarWhenPushed = true
                self.navigationController?.pushViewController(v, animated: true)
            }
        }else if indexPath.row == 3 {
        
            let paste = UIPasteboard.general
            paste.string = "daikuanyijk"
            
            let alert = UIAlertController.init(title: "复制公众号成功！请打开微信关注", message: nil, preferredStyle: .alert)
            let alertCancelAction: UIAlertAction = UIAlertAction.init(title: "确认", style: UIAlertActionStyle.cancel, handler: nil)
            
            alert.addAction(alertCancelAction)
            self.present(alert, animated: true, completion: nil)
        }else {
        
            if let v = FCMessageViewController.create() as? FCMessageViewController {
                v.hidesBottomBarWhenPushed = true
                self.navigationController?.pushViewController(v, animated: true)
            }
        
        }
    }
    
    
    @IBAction func exitAction(_ sender: Any) {

        
        if let v = FCLoginViewController.create() as? FCLoginViewController {
        
            self.navigationController?.isNavigationBarHidden = true
            v.hidesBottomBarWhenPushed = true
            FCModelData.instance.isLogin = false
            self.navigationController?.pushViewController(v, animated: true)

            
            
        }
        
    
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    


}
